#include <bits/stdc++.h>
#define F(i,l,r) for(int i=(l);i<=(r);i++)
#define DF(i,l,r) for(int i=(l);i>=(r);i--)
#define ms(x,y) memset(x,y,sizeof(x))
#define SZ(x) (int)x.size()-1
#define pb push_back
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int> pii;
template<typename T> void chkmin(T &x,T y){ x=min(x,y);}
template<typename T> void chkmax(T &x,T y){ x=max(x,y);}
template<typename T> void read(T &x){
    x=0;int r=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') r=-1;
    for(;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-48;
    x*=r;
}
const int N=100010;
int n,m,L,V,tes[N],lmt[N],f[N];
struct Info{ int d,v,a;}car[N];
bool chk(int id,int pos){
    if(car[id].d>pos) return 0;
    LL qwq=1ll*car[id].v*car[id].v+2ll*car[id].a*(pos-car[id].d);
    return qwq>1ll*V*V;
}
void work(){
    read(n),read(m),read(L),read(V);
    F(i,1,n){
        int d,v,a;read(d),read(v),read(a);
        car[i]={d,v,a};
    }
    F(i,1,m) read(tes[i]);
    F(i,1,m) lmt[i]=0;
    int ans1=0;
    F(i,1,n){
        if(car[i].a>0){
            int lo=0,hi=m+1;
            while(lo<hi-1){
                int mid=(lo+hi)>>1;
                if(chk(i,tes[mid])) hi=mid;
                else lo=mid;
            }
            if(hi<=m) ans1++,chkmax(lmt[m],hi);
        }
        else if(car[i].a==0){
            if(car[i].v>V&&tes[m]>=car[i].d){
                ans1++;
                int p=lower_bound(tes+1,tes+m+1,car[i].d)-tes;
                chkmax(lmt[m],p);
            }
        }
        else{
            int p=lower_bound(tes+1,tes+m+1,car[i].d)-tes;
            int lo=p-1,hi=m+1;
            while(lo<hi-1){
                int mid=(lo+hi)>>1;
                if(chk(i,tes[mid])) lo=mid;
                else hi=mid;
            }
            if(lo&&p<=lo) ans1++,chkmax(lmt[lo],p);
        }
    }
    f[0]=0;
    int p=0;
    F(i,1,m) f[i]=f[p]+1,chkmax(p,lmt[i]);
    printf("%d %d\n",ans1,m-f[p]);
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;read(T);
    while(T--) work();
    return 0;
}
